package cn.z2huo.leetcode.problem.NO_0009;

/*
* 判断一个整数是否是回文数
* 将整数转换为字符串向字符串的首尾依次进行比较
*
* */

public class Main {
    public boolean resolve(int demo){
        if(demo>=0){
            String str = String.valueOf(demo);
            // 在字符串的头和尾指定头指针和尾指针，头尾同时遍历判断是否相等
            int low = 0, high=str.length()-1;
            while(low<=high){
                char left = str.charAt(low);
                char right = str.charAt(high);
                if(left == right){
                    low ++;
                    high --;
                }else{
                    return false;
                }
            }
        }else{
            System.out.println("输入的是负数，不是回文数！");
            return false;
        }
        return true;
    }

    public static void main(String[] args){
        int testInt = 1221;
        Main m = new Main();
        if(m.resolve(testInt)){
            System.out.println("输入的数是回文数！");
        }else{
            System.out.println("输入的数不是回文数！");
        }
    }
}